/*
 * Principal.java
 *
 * Created on 5 de Junho de 2008, 16:41
 * 
 * Janela Principal da Aplicação.
 */

package inventario.gui;

import javax.swing.*;  
import java.awt.event.*;  
import java.awt.*;  
import inventario.regras.*;
import java.io.IOException;

/**
 *
 * @author  mdneto
 */
public class Principal extends javax.swing.JFrame {
    
    private ProdutoLista lista;
    
    /** Creates new form Principal */
    public Principal() {
        lista = new ProdutoLista();
        
        initComponents();
        this.setSize(450, 350);
        this.setLocation(100, 200);
        this.setVisible(true);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jButton2 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        edCodigo = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        edNome = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        edQuantidade = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        edValor = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jButton5 = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Janela Principal");
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        getContentPane().setLayout(null);

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel1.setLayout(null);

        jButton2.setText("Alterar");
        jPanel1.add(jButton2);
        jButton2.setBounds(20, 70, 110, 25);

        jButton4.setText("Remover");
        jPanel1.add(jButton4);
        jButton4.setBounds(20, 110, 110, 25);

        jButton6.setText("Incluir");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton6);
        jButton6.setBounds(20, 30, 110, 25);

        getContentPane().add(jPanel1);
        jPanel1.setBounds(10, 70, 150, 160);

        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel2.setLayout(null);

        jLabel2.setText("Código");
        jPanel2.add(jLabel2);
        jLabel2.setBounds(13, 20, 60, 14);
        jPanel2.add(edCodigo);
        edCodigo.setBounds(90, 20, 160, 19);

        jLabel3.setText("Nome");
        jPanel2.add(jLabel3);
        jLabel3.setBounds(17, 50, 60, 14);
        jPanel2.add(edNome);
        edNome.setBounds(90, 50, 160, 19);

        jLabel4.setText("Quantidade");
        jPanel2.add(jLabel4);
        jLabel4.setBounds(16, 80, 60, 14);
        jPanel2.add(edQuantidade);
        edQuantidade.setBounds(90, 80, 160, 19);

        jLabel5.setText("Valor");
        jPanel2.add(jLabel5);
        jLabel5.setBounds(14, 110, 60, 14);
        jPanel2.add(edValor);
        edValor.setBounds(90, 110, 160, 19);

        getContentPane().add(jPanel2);
        jPanel2.setBounds(170, 70, 260, 160);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel1.setText("Sistema de Inventário");
        getContentPane().add(jLabel1);
        jLabel1.setBounds(140, 20, 170, 17);

        jButton5.setText("Fechar");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton5);
        jButton5.setBounds(320, 260, 100, 23);

        jButton1.setText("Próximo");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton1);
        jButton1.setBounds(180, 260, 110, 23);

        jButton7.setText("Anterior");
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton7);
        jButton7.setBounds(33, 260, 120, 23);
    }// </editor-fold>//GEN-END:initComponents

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        try {
            lista.arrayListParaArquivo();
        }
        catch (IOException e){
        }
        
        System.exit(0);
    }//GEN-LAST:event_jButton5ActionPerformed

private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
    if ( lista.listaVazia() )
        JOptionPane.showMessageDialog(null, "Lista Vazia!");
    else {
        
    }
}//GEN-LAST:event_jButton7ActionPerformed

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    if ( lista.listaVazia() )
        JOptionPane.showMessageDialog(null, "Lista Vazia!");
    else {
        
    }
}//GEN-LAST:event_jButton1ActionPerformed

private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
    String texto;
    
    texto = edCodigo.getText() + ","
          + edNome.getText() + ","  
          + edQuantidade.getText() + ","  
          + edValor.getText();
    
    lista.incluirLista( new Produto(texto) );
}//GEN-LAST:event_jButton6ActionPerformed
    

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField edCodigo;
    private javax.swing.JTextField edNome;
    private javax.swing.JTextField edQuantidade;
    private javax.swing.JTextField edValor;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    // End of variables declaration//GEN-END:variables
    
}
